#ifndef PLAYER_H
#define PLAYER_H
#include <SDL/SDL.h>
#include <vector>

#include "src/utils/net_server.h"
#include "car.h"

class Player
{
	public:
		Player( unsigned int id ) : m_name(""), m_approved(false), m_joined(false), m_inputtype(KEYBOARD), m_local(true), m_id(id), m_time(0), m_connecttime(0)
		{
			cout << "player " << m_id << " connected" << endl;
		};

		virtual ~Player(  )
		{
			cout << "exiting player" << endl;
			unjoin();
		};
		
		void approve() { m_approved = true; }
		bool isApproved() { return m_approved; }

		bool isJoined() { return m_joined; }
		bool isLocal() { return m_local; }

		void join( boost::shared_ptr<Car> car )
		{
			m_car = car;
			m_joined = true;
		}
		void unjoin(  )
		{
			if ( isJoined() )
			{
				m_joined = false;
				m_car=boost::shared_ptr<Car>();
			}
		}
		boost::shared_ptr<Car> getCar() { return m_car; }

		unsigned int getId() { return m_id; }
		
		unsigned int getConnecttime() { return m_connecttime; }

		unsigned int getTime() { return m_time; }
		void setTime( unsigned int time ) { m_time = time; }

		Inputtype getInputtype() { return m_inputtype; }
		void setInputtype( Inputtype inputtype ) { m_inputtype = inputtype; }

		boost::shared_ptr<nClient> getNetworkclient() { return m_networkclient; }
		void setNetworkInfo( boost::shared_ptr<nClient> networkclient )
		{
			m_networkclient = networkclient;
			m_local = false;
		}

		void pushOutgoingmessage( const string& message )
		{
			m_messages_out.push_back(message);
		}

		void pushIncomingmessage( const string& message )
		{
			m_messages_in.push_back(message);
		}

		vector<string>	m_messages_in;
		vector<string>	m_messages_out;
	private:
		string m_name;
		boost::shared_ptr<Car> m_car;
		bool m_approved;
		bool m_joined;
		Inputtype m_inputtype;
		bool m_local;
		unsigned int m_id;
		boost::shared_ptr<nClient> m_networkclient;


		unsigned int m_time;
		unsigned int m_connecttime;
};


#endif
